import numpy as np

import pandas as pd

import pyecharts

class ChipotleAna:
    path = r'C:\Users\我是夜雨吖\Desktop\python第七个月（北网）\张鹏举课堂代码\pandas_exercises\01_Getting_&_Knowing_Your_Data\Chipotle\chipotle.csv'
    def __init__(self):

        self.df = pd.read_csv(self.path,sep = '\t')



    def echarts_bar(self,series,bar_name = 'test',name = 'test_name'):

        bar = pyecharts.Bar(bar_name)
        axis0=series.index
        axis1=series.values.ravel()
        bar.add(name,axis0,axis1,is_stack=True,is_label_show=True, is_datazoom_show=True)
        return bar







    def how_many_sold_per_item(self):
        '''
        每个商品卖多少个
        '''
        count_info = self.df.groupby('item_name').sum()

        count_info = count_info.drop('order_id',axis=1)

        return count_info

    def bar_how_many_sold_per_item(self):

        return self.echarts_bar(self.how_many_sold_per_item())




    def how_much_sold_per_item(self):
        x=self.df.quantity * (self.df.item_price.str.replace("$", "").astype("float64"))
        df1=self.df.copy()
        df1['price']=round(x,2)
        df1=df1.groupby('item_name').sum()
        df1.drop('order_id',axis=1,inplace = True)
        df1.drop('quantity',axis=1,inplace = True)
        return round(df1['price'],2)

    def bar_how_much_sold_per_item(self):
        return self.echarts_bar(self.how_much_sold_per_item(),bar_name='每种商品总收入')
